//
//  OutPatientViewController.m
//  掌上宏力
//
//  Created by admin on 2017/4/26.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "OutPatientViewController.h"
#import "OuptMainModel.h"
#import "OuptMainCell.h"
#import "OuptPrescribeVC.h"
#import "OutPatientViewModel.h"

@interface OutPatientViewController ()

@property (nonatomic,strong) OutPatientViewModel *viewModel;

@end

@implementation OutPatientViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"就诊记录";
}
-(void)getDatasArray{
    [self getDatasArray:^(NSString *page, GetDatas handler) {
        _viewModel = [[OutPatientViewModel alloc] init];
        [_viewModel getOutPatient:^{
            if (self.currentPage == 1) {
                handler(_viewModel.datasArray);
                [self.tableView.mj_footer endRefreshingWithNoMoreData];
            }else{
                handler([NSArray array]);
                [SVProgressHUD showErrorWithStatus:@"暂无更多数据"];
            }
        }];
    }];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 100;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 35;
}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    OuptMainModel *model = _viewModel.datasArray[section];
    return model.visitDate;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    OuptPrescribeVC *prescVC = [[OuptPrescribeVC alloc] init];
    prescVC.ouptModel = _viewModel.datasArray[indexPath.section];;
    [self pushViewControllerTo:prescVC];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    OuptMainCell *cell = [OuptMainCell cellWithTableView:tableView];
    cell.ouptMain = _viewModel.datasArray[indexPath.section];
    return cell;
}


@end
